//
//  YYDeviceOtherStateView.m
//  Project
//
//  Created by Yown on 2024/1/25.
//

#import "YYDeviceOtherStateView.h"

#import <BIToolModule/BIProjectDefine.h>
#import <BIRouteModule/BIRouteManager.h>

#import <BIProjectModule/BIAppDefine.h>
#import <BIToolModule/UIView+RotationAnimation.h>

@interface YYDeviceOtherStateView ()

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UILabel *textLabel;

@end

@implementation YYDeviceOtherStateView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.backgroundColor = [UIColor clearColor];
    
    self.textLabel.textColor = [UIColor loadColorFromString:@"#828282"];
    self.textLabel.font = BIFont(14);
    
    self.userInteractionEnabled = YES;
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickTapGesture:)]];
}

- (void)reloadDeviceState:(BIBluetoothState)state {
    if (state == kBIBluetoothConnecting) {
        self.textLabel.text = BILocalizedString(@"home_connecting");
        self.imageView.image = [UIImage imageNamed:@"home_device_connecting"];
        [self.imageView stopAnimationnimationWithType:kBIAnimationRotationType];
        [self.imageView startAnimationWithType:kBIAnimationRotationType duration:2.0];
        self.hidden = NO;
        self.userInteractionEnabled = NO;
    } else if (state == kBIBluetoothDisconnected) {
        self.textLabel.text = BILocalizedString(@"home_disconnect");
        self.imageView.image = [UIImage imageNamed:@"home_device_disconnect"];
        [self.imageView stopAnimationnimationWithType:kBIAnimationRotationType];
        self.hidden = NO;
        self.userInteractionEnabled = YES;
    } else {
        [self.imageView stopAnimationnimationWithType:kBIAnimationRotationType];
        self.hidden = YES;
        self.userInteractionEnabled = NO;
    }
}

- (void)clickTapGesture:(UITapGestureRecognizer *)tapGesture {
    [[BIRouteManager sharedInstance] openVCCMD:@"bluetoothScan" isPresent:NO arguments:nil];
}

@end
